// spoj10628 COT
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define MAXN 100005
#define MAXD 18
using namespace std;
int n, k, w[MAXN], d[MAXN], dep[MAXN], dp[MAXD][MAXN];
vector<int>e[MAXN];

class Segment_Tree{
	private:
		int tot;
		struct Node{
			int sum;
			int l, r;
		}node[MAXN * 20];
	public:
		int root[MAXN];
		void clear(){ tot = 0; }
		int build(int l = 1, int r = k){
			int rt = tot++;
			node[rt].sum = 0;
			if (l == r) return rt;
			int m = (l + r) >> 1;
			node[rt].l = build(l, m);
			node[rt].r = build(m + 1, r);
			return rt;
		}
		int update(int P, int val, int i, int l = 1, int r = k){
			int rt = tot++;
			node[rt] = node[i];
			node[rt].sum += val;
			if (l == r) return rt;
			int m = (l + r) >> 1;
			if (P <= m) node[rt].l = update(P, val, node[i].l, l, m);
			else node[rt].r = update(P, val, node[i].r, m + 1, r);
			return rt;
		}
		int query(int k, int Li, int Ri, int LCAi, int FLCAi, int l = 1, int r = k){
			if (l == r) return l;
			int m = (l + r) >> 1;
			int cnt = node[node[Li].l].sum + node[node[Ri].l].sum - node[node[LCAi].l].sum - node[node[FLCAi].l].sum;
			if (k <= cnt)
				return query(k, node[Li].l, node[Ri].l, node[LCAi].l, node[FLCAi].l, l, m);
			else
				return query(k - cnt, node[Li].r, node[Ri].r, node[LCAi].r, node[FLCAi].r, m + 1, r);
		}
}seg;

void dfs(int fa, int u){
	for (int i = 1; i < MAXD; i++)
		dp[i][u] = dp[i - 1][dp[i - 1][u]];
	seg.root[u] = seg.update(w[u], 1, seg.root[fa]);
	for (int i = 0; i < e[u].size(); i++){
		int v = e[u][i];
		if (fa != v){
			dep[v] = dep[u] + 1;
			dp[0][v] = u;
			dfs(u, v);
		}
	}
}

int lca(int u, int v){
	if (dep[u] > dep[v]) swap(u, v);
	int delta = dep[v] - dep[u];
	for (int i = MAXD - 1; i >= 0; i--)
		if (delta & (1 << i)) v = dp[i][v];
	if (u == v) return u;
	for (int i = MAXD - 1; i >= 0; i--){
		if (dp[i][u] != dp[i][v]){
			u = dp[i][u];
			v = dp[i][v];
		}
	}
	return dp[0][u];
}

int main(){
#ifdef _DEBUG
	freopen("f:\\COT.txt", "r", stdin);
#endif
	int m, u, v, x;
	while (scanf("%d %d", &n, &m) != EOF){
		for (int i = 1; i <= n; i++) e[i].clear();
		for (int i = 1; i <= n; i++)
			scanf("%d", w + i);
		memcpy(d + 1, w + 1, sizeof(int) * n);
		sort(d + 1, d + n + 1);
		k = unique(d + 1, d + n + 1) - d - 1;
		for (int i = 1; i <= n; i++)
			w[i] = lower_bound(d + 1, d + k + 1, w[i]) - d;
		for (int i = 1; i < n; i++){
			scanf("%d %d", &u, &v);
			e[u].push_back(v);
			e[v].push_back(u);
		}
		seg.clear();
		seg.root[0] = seg.build();
		dfs(-1, 1);
		for (int i = 0; i < m; i++){
			scanf("%d %d %d", &u, &v, &x);
			int rt = lca(u, v);
			int p = seg.query(x, seg.root[u], seg.root[v], seg.root[rt], seg.root[dp[0][rt]]);
			printf("%d\n", d[p]);
		}
	}
}

